package com.hongruan.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.hongruan.bean.Account;
import com.hongruan.dao.AccountDao;

@Repository
public class AccountDaoImpl extends GenericDaoHibernateImpl<Account, Long> implements AccountDao {
	public AccountDaoImpl() {
		super(Account.class);
	}

	public List<Account> accountList(Account account) {
        String hql = "select a.id as id,s.mc as swjgName,a.userName as userName,a.yhxm as yhxm,a.yhsfzh as yhsfzh,a.sex as sex,a.birthDate as birthDate, " +
        		"a.xl as xl,a.userphone as userphone,a.usertype as usertype,a.xybz as xybz " +
				"from Account a,Swjg s where a.swjgId = s.id ";

        String sql = "select a.id as id,s.mc as swjgName,a.userName as userName,a.yhxm as yhxm,a.yhsfzh as yhsfzh,a.sex as sex,a.birthDate as birthDate, " +
		"a.xl as xl,a.userphone as userphone,a.usertype as usertype,a.xybz as xybz " +
		"from t_account a,t_swjg s where a.swjgId = s.id and a.isdel = 0";
        
		Query query = this.getCurrentSession().createQuery(hql)
		        .setResultTransformer(Transformers.aliasToBean(Account.class));
		Query query2 = this.getCurrentSession().createSQLQuery(sql).addScalar("id").addScalar("swjgName").addScalar("userName").addScalar("yhxm")
				.addScalar("yhsfzh").addScalar("sex").addScalar("birthDate").addScalar("xl").addScalar("userphone").addScalar("usertype")
				.addScalar("xybz");
		return query2.list();
	}
}
